import request from '@/utils/request'

/**
 * 登录
 * @param {string} mobile 手机号
 * @param {string} code 验证码
 * @returns Promise对象
 */
export const loginAPI = (mobile, code) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}

/**
 * 获取验证码
 * @param{string} mobile 手机号
 * @returns Promise
 */

export const getCodeAPI = (mobile) => {
  return request({
    url: `/v1_0/sms/codes/${mobile}`
  })
}

export const getUserInfoAPI = () => {
  return request({
    url: '/v1_0/user'
  })
}

export const getUserProfileAPI = () => {
  return request({
    url: '/v1_0/user/profile'
  })
}

export const editUserProfileAPI = (data) => {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data
  })
}
export const uploadPhoto = (file) => {
  const fm = new FormData()
  fm.append('photo', file)
  return request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: fm
  })
}
/**
 * 关注用户
 * @param {*} target
 * @returns
 */
export const addFollow = target => {
  return request({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target
    }
  })
}

/**
 * 取消用户
 * 
 * @returns
 */
export const deleteFollow = target => {
  return request({
    method: 'DELETE',
    url: `/v1_0/user/followings/${target}`
  })
}
